package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.bean.FaHuoBean
import com.erp.module.faHuoDanJu.FaHuoDanJuContract
import com.erp.R
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.fahuoonum_lv_item.view.*

/**
 * Created by Administrator on 2018/11/9/009.
 * 作者：刘洋
 */
class FaHuoOnumAdapter(var context: Context, var KView : FaHuoDanJuContract.FaHuoCarKView, var list: MutableList<FaHuoBean.onum>) : BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        var h : ViewHolder
        if(convertView==null){
//            v = minflater.inflate(R.layout.lv_fahuo_item,null)
            v = minflater.inflate(R.layout.fahuoonum_lv_item,null)
            h = ViewHolder(v)
            v.tag=h
        }else{
            v = convertView
            h = v.tag as ViewHolder
        }
        var bean = list[position]
        Myutil.settv(bean.onum,h.TvOnum)
        return v
    }

    override fun getItem(position: Int): Any {
        return list[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return  list.size
    }
    class ViewHolder(var v : View){
        //        var titletextview = v.dragsort_listview_item_textview
        var TvOnum = v.TvOnum
    }

    fun remove(arg0: Int) {// 删除指定位置的item
        list.removeAt(arg0)
        this.notifyDataSetChanged()// 不要忘记更改适配器对象的数据源
    }

    fun insert(item: FaHuoBean.onum, arg0: Int) {// 在指定位置插入item
        list.add(arg0, item)
        this.notifyDataSetChanged()
    }
}